package p23_类型转换与绑定;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: az
 * @Date: 2023-04-29 20:05
 * @Version: 1.0
 */
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class Boot {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Boot.class);
        Map<String, Controller> beansOfType = context.getBeansOfType(Controller.class);
        System.out.println(beansOfType);
        //context.close();

    }

    @Component("test")
    static class Test {
        private String name;
        public void foo() {
            System.out.println("foo方法...");
        }
    }

    @Aspect
    @Component
    static class Aop {
        @Before("execution(* foo())")
        public void before() {
            System.out.println("before...");
        }
    }

    @Component("/c1")
    static class Controller1 implements Controller {

        @Override
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
            response.getWriter().printf("hahahah");
            return null;
        }
    }

    @Component
    static class A implements BeanFactoryPostProcessor {

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            System.out.println("自定义bean后处理器");
        }
    }
}
